@extends('layouts.app')

@section('title')
    后台-字典管理
@stop

@section('extcss')
    <!--ext css-->
    <!--bootstrap treeview-->
    <link href="//cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css" rel="stylesheet">
    <!-- /ext css-->
@stop

@section('content')
    <!-- page content -->
    <div class="right_col" role="main">
        <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>字典管理</h3>
                </div>

                <div class="title_right">
                    &nbsp;
                </div>
            </div>

            <div class="clearfix"></div>

            <div class="row">
                <div class="col-md-9 col-xs-12 col-sm-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>字典列表</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">

                            <div id="tree"></div>
                            <div class="row">
                                @if($errors->any())
                                    <div class="ln_solid"></div>
                                    <ul class="list-group">
                                        @foreach($errors->all() as $error)
                                            <li class="list-group-item list-group-item-danger">{{$error}}</li>
                                        @endforeach
                                    </ul>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-xs-12 col-sm-12">
                        <form id="dicForm" method="post" action="{{url('system/dic')}}" class="form-horizontal form-label-left">
                            {!!csrf_field()!!}
                            <div class="x_panel">
                                <div class="x_title">
                                    <h2>增加字典</h2>
                                    <ul class="nav navbar-right panel_toolbox">
                                        <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                        </li>
                                    </ul>
                                    <div class="clearfix"></div>
                                </div>
                                <div class="x_content">
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="nodeParentText">归属节点 <span
                                                    class="required">*</span>
                                        </label>

                                        <div class="col-md-9 col-sm-12 col-xs-12">
                                            <input type="text" id="nodeParentText" name="nodeParentText" class="form-control" value="根节点" readonly>
                                            <input type="hidden" id="parent_id" name="parent_id" value="0">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="nodeName">节点名称 <span
                                                    class="required">*</span>
                                        </label>

                                        <div class="col-md-9 col-sm-12 col-xs-12">
                                            <input type="text" id="key" name="key" class="form-control" required="required">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="nodeVal">节点数值 <span
                                                    class="required">*</span>
                                        </label>

                                        <div class="col-md-9 col-sm-12 col-xs-12">
                                            <input type="text" id="val" name="val" class="form-control" required="required">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="selProvince">备注 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-9 col-md-offset-3 col-sm-12 col-xs-12">
                                            <textarea id="remark" name="remark" class="form-control col-md-7 col-xs-12"></textarea>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-6 text-center">
                                            <button id="send" type="submit" class="btn btn-success">提交</button>
                                        </div>
                                        <div class="col-md-6 text-center">
                                            <button type="button" class="btn btn-default">取消</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@stop

@section('extjs')
    <!--ext js-->
    <!--bootstrap treeview-->
    <script src="//cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
    <!-- Parsley -->
    <script src="{{asset("vendors/parsleyjs/dist/parsley.min.js")}}"></script>
    <script src="{{asset("vendors/parsleyjs/dist/i18n/zh_cn.js")}}"></script>

    <!--Parsley-->
    <script type="text/javascript">
        $(function () {
            $('#dicForm').parsley().on('field:validated', function() {
                var ok = $('.parsley-error').length === 0;
                $('.bs-callout-info').toggleClass('hidden', !ok);
                $('.bs-callout-warning').toggleClass('hidden', ok);
            }).on('form:submit', function() {
                $(this).submit();
            });
        });
    </script>
    <!-- /Parsley-->

    <!--customer js-->
    <script>
        function getTree() {

            var tree = [
                {
                    text:"根节点",
                    Extendible:{!! json_encode($dics->toarray()) !!},
                }
            ];

            return tree;
        }

        $('#tree').treeview({data: getTree()});


        $('#tree').on('nodeSelected', function(event, data) {

            $("#parent_id").val(data.Extendible.id);
            $("#nodeParentText").val(data.text);

            {{--$.ajax({--}}
                {{--url: "{{url('system/dic/')}}/"+data.Extendible.id--}}
                {{--, async: true--}}
                {{--, type: "get"--}}
                {{--, success: function (result) {--}}
                    {{--alert(result);--}}
                {{--}--}}
            {{--});--}}
        });
    </script>
    <!--customer js-->
    <!-- /ext js-->
@stop